﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Inovance.InoMotionCotrollerShop.InoServiceContract.EtherCATConfigApi;
namespace example
{
    public partial class Form1 : Form
    {
        public List<int> mCaptPosList;
        public static UInt64 cardHandle;//轴卡操作句柄
        UInt32 retRtn; //函数接口返回值
        Int16 axNo = 0;//起始轴号
        Int16 count = 3;//轴数
        Int16 stopType = 1;//停止类型 0： 平滑停止 1： 急速停止
        //Int16 sysNo = 0;//系统号， [0,1]
        Int16[] MaskAxNoArray = { 0,1,2 };//建立系统的各轴的轴号。该指针为数组指针， 应输入数组长度由 maxAxNum 决定
        //Int16 maxAxNum=3;//建立系统的轴数量： [1,16]

        public Form1()
        {
            InitializeComponent();
        }

        #region 初始化
        //打印日志
        private void ShowMessage(string msg)
        {            
            listBox_RunSts.Items.Add(DateTime.Now.ToString() + " " + msg);
            listBox_RunSts.SelectedIndex = listBox_RunSts.Items.Count - 1;
            listBox_RunSts.SelectedIndex = -1;
        }
        //卡初始化
        private void button_CardInit_Click(object sender, EventArgs e)
        {
            UInt32 masterStatus = 0;
            int cardNo = 0; //打开0号卡
            Int32 cardsNum = 0;
            try
            {
                //非必须步骤，读取电脑中轴卡的数量
                retRtn = ImcApi.IMC_GetCardsNum(ref cardsNum);
                if (retRtn != ImcApi.EXE_SUCCESS)
                {
                    ShowMessage("IMC_GetCardsNum failed 故障代码为：0x" + retRtn.ToString("x8"));
                }
                textBox_CardNum.Text = cardsNum.ToString();
                //【1】获取轴卡操作句柄
                retRtn = ImcApi.IMC_OpenCardHandle(cardNo, ref cardHandle);
                if (retRtn != ImcApi.EXE_SUCCESS)
                {
                    ShowMessage("IMC_OpenCardHandle failed 故障代码为：0x" + retRtn.ToString("x8"));
                }
                //【2】获取主站状态
                retRtn = ImcApi.IMC_GetECATMasterSts(cardHandle, ref masterStatus);
                if (retRtn != ImcApi.EXE_SUCCESS)
                {
                    ShowMessage("IMC_GetECATMasterSts failed 故障代码为：0x" + retRtn.ToString("x8"));
                }
                else
                {
                    if (masterStatus != ImcApi.EC_MASTER_OP)
                    {
                        //【3】下载设备参数
                        //deviceconfig.xml文件是由控制卡后台软件配置生成然后手动放到编译路径下，路径可自由选择；
                        retRtn = ImcApi.IMC_DownLoadDeviceConfig(cardHandle, ".\\deviceconfig.xml");
                        if (retRtn != ImcApi.EXE_SUCCESS)
                        {
                            ShowMessage("IMC_DownLoadDeviceConfig failed 故障代码为：0x" + retRtn.ToString("x8"));
                        }
                        //【4】启动总线
                        retRtn = ImcApi.IMC_ScanCardECAT(cardHandle, 1);            //0表示非阻塞式开卡，1表示阻塞式开卡；
                        if (retRtn != ImcApi.EXE_SUCCESS)
                        {
                            ShowMessage("IMC_ScanCardECAT failed 故障代码为：0x" + retRtn.ToString("x8"));
                        }
                        //【5】下载系统参数
                        //systemconfig.xml文件是由控制卡后台软件配置生成然后手动放到编译路径下，路径可自由选择；
                        retRtn = ImcApi.IMC_DownLoadSystemConfig(cardHandle, ".\\systemconfig.xml");
                        if (retRtn != ImcApi.EXE_SUCCESS)
                        {
                            ShowMessage("IMC_DownLoadSystemConfig failed 故障代码为：0x" + retRtn.ToString("x8"));
                        }
                    }
                }
                timer_UI.Enabled = true;
                textBox_CardNum.Text = cardsNum.ToString();
            }
            catch (Exception ex)
            {
                ShowMessage(ex.ToString());
            }
        }
        //关闭卡
        private void button_CloseCard_Click(object sender, EventArgs e)
        {
            try
            {
                timer_UI.Enabled = false;
                retRtn = ImcApi.IMC_CloseCard(cardHandle);
                //retRtn = ImcApi.IMC_CloseCardHandle(cardHandle);
                if (retRtn != ImcApi.EXE_SUCCESS)
                {
                    ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " failed 故障代码为：0x" + retRtn.ToString("x8"));
                    return;
                }
            }
            catch (Exception ex)
            {
                ShowMessage(ex.ToString());
            }
        }
        #endregion

        #region 控制
        //使能
        private void button_AxServoOn_Click(object sender, EventArgs e)
        {
            try
            {
                retRtn = ImcApi.IMC_AxServoOn(cardHandle, axNo, count);
                if (retRtn != ImcApi.EXE_SUCCESS)
                {
                    ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " failed 故障代码为：0x" + retRtn.ToString("x8"));
                    return;
                }
                else
                {
                    ShowMessage("轴上使能成功");
                }
            }
            catch (Exception ex)
            {
                ShowMessage(ex.ToString());
            }
        }
        //下使能
        private void button_AxServoOff_Click(object sender, EventArgs e)
        {
            try
            {
                retRtn = ImcApi.IMC_AxServoOff(cardHandle, axNo, count);
                if (retRtn != ImcApi.EXE_SUCCESS)
                {
                    ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " failed 故障代码为：0x" + retRtn.ToString("x8"));
                    return;
                }
                else
                {
                    ShowMessage("轴上失能成功");
                }
            }
            catch (Exception ex)
            {
                ShowMessage(ex.ToString());
            }
        }
        //停止
        private void button_AxMoveStop_Click(object sender, EventArgs e)
        {
            try
            {
                stopType = 1;//停止类型 0： 平滑停止 1： 急速停止
                retRtn = ImcApi.IMC_AxMoveStop(cardHandle, axNo, stopType);// 0平滑停止；1 急停停止
                if (retRtn != ImcApi.EXE_SUCCESS)
                {
                    ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " failed 故障代码为：0x" + retRtn.ToString("x8"));
                    return;
                }
            }
            catch (Exception ex)
            {
                ShowMessage(ex.ToString());
            }
        }
        //清除轴状态
        private void button_ClrAxSts_Click(object sender, EventArgs e)
        {
            try
            {
                for (Int16 i = axNo; i < count; i++)
                {
                    retRtn = ImcApi.IMC_ClrAxSts(cardHandle, i);
                }
                if (retRtn != ImcApi.EXE_SUCCESS)
                {
                    ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " failed 故障代码为：0x" + retRtn.ToString("x8"));
                    return;
                }
            }
            catch (Exception ex)
            {
                ShowMessage(ex.ToString());
            }
        }
        #endregion

        #region 轴状态与信息显示
        //将十进制整形转换为二进制显示的字符串
        private string ConvertDecimalToBinary(Int32 nAxSts) 
        {
            string strAxSts = "";
            Int32 nBitValue = 0x00;

            for (uint i = 0; i < 11; i++)
            {
                nBitValue = (Int32)(0x01 * Math.Pow(2.0, i));    //对nBitValue向左移1位，移到第几位通过i来控制
                if ((nAxSts & nBitValue) == nBitValue)
                {
                    strAxSts = "1" + strAxSts;
                }
                else
                {
                    strAxSts = "0" + strAxSts;
                }
            }
            return strAxSts;
        }
        //UI界面信息刷新
        private void timer_UI_Tick(object sender, EventArgs e)
        {
            try
            {
                timer_UI.Enabled = false;
                double[] PrfPosArray = { 0, 0, 0 };
                double[] EncPosArray = { 0, 0, 0 };
                double[] EncVelArray = { 0, 0, 0 };
                Int32[] AxStsArray = { 0, 0, 0 };
                //Int16 Space = 0;//当前系统剩余的数据空间
                Int16 Status0 = 0;//0： 停止状态 1： 运动状态
                Int16 IncMode = 0;//0：绝对位置编程 1：相对位置编程
                Int16[] EnSts = { 0, 0, 0 };//保护使能状态
                double[] ThresholdVel = { 0, 0, 0 };//各轴的保护速度阈值， 该参数为数组首地址
                Int16 Err = 0;//0： 无错误 1：断流错误 2：系统中某一单轴出现报警错误
                //Int16 crdNo = 0;//打开0号卡
                Int16 Sts = 0;//到位状态
                Int16 Empty = 0;//0：空闲 1：忙碌

                //获取目标位置
                retRtn = ImcApi.IMC_GetAxPrfPos(cardHandle, axNo, PrfPosArray, count);
                if (retRtn != ImcApi.EXE_SUCCESS)
                {
                    ShowMessage("IMC_GetAxSts failed 故障代码为：0x" + retRtn.ToString("x8"));
                    return;
                }
                //获取反馈位置
                retRtn = ImcApi.IMC_GetAxEncPos(cardHandle, axNo, EncPosArray, count);
                if (retRtn != ImcApi.EXE_SUCCESS)
                {
                    ShowMessage("IMC_GetAxEncPos failed 故障代码为：0x" + retRtn.ToString("x8"));
                    return;
                }
                //获取反馈速度
                retRtn = ImcApi.IMC_GetAxEncVel(cardHandle, axNo, EncVelArray, count);
                if (retRtn != ImcApi.EXE_SUCCESS)
                {
                    ShowMessage("IMC_GetAxSts failed 故障代码为：0x" + retRtn.ToString("x8"));
                    return;
                }
                //获取伺服状态
                retRtn = ImcApi.IMC_GetAxSts(cardHandle, axNo, AxStsArray, count);
                if (retRtn != ImcApi.EXE_SUCCESS)
                {
                    ShowMessage("IMC_GetAxSts failed 故障代码为：0x" + retRtn.ToString("x8"));
                    return;
                }                

                //目标位置
                textBox_AxPrfPos0.Text = PrfPosArray[0].ToString();
                textBox_AxPrfPos1.Text = PrfPosArray[1].ToString();
                textBox_AxPrfPos2.Text = PrfPosArray[2].ToString();
                //反馈位置
                textBox_AxEncPos0.Text = EncPosArray[0].ToString();
                textBox_AxEncPos1.Text = EncPosArray[1].ToString();
                textBox_AxEncPos2.Text = EncPosArray[2].ToString();
                //反馈速度
                textBox_AxEncVel0.Text = EncVelArray[0].ToString();
                textBox_AxEncVel1.Text = EncVelArray[1].ToString();
                textBox_AxEncVel2.Text = EncVelArray[2].ToString();
                //伺服状态
                textBox_AxSts0.Text = ConvertDecimalToBinary(AxStsArray[0]);//转化为二进制字符串显示
                textBox_AxSts1.Text = ConvertDecimalToBinary(AxStsArray[1]);
                textBox_AxSts2.Text = ConvertDecimalToBinary(AxStsArray[2]);                
                //到位状态
                textBox_AxStsArrive0.Text = (AxStsArray[0] & 0xC) == 0x8 ? "1" : "0";
                textBox_AxStsArrive1.Text = (AxStsArray[1] & 0xC) == 0x8 ? "1" : "0";
                textBox_AxStsArrive2.Text = (AxStsArray[2] & 0xC) == 0x8 ? "1" : "0";
                if ((AxStsArray[0] & ImcApi.AX_BUSY_BIT) == ImcApi.AX_BUSY_BIT)
                {
                    ////获取捆绑 PT 运动数据的空间
                    //retRtn = ImcApi.IMC_GetPtPackRestSpace(cardHandle, axNo, ref Space);
                    //if (retRtn != ImcApi.EXE_SUCCESS)
                    //{
                    //    ShowMessage("IMC_GetPtPackRestSpace failed 故障代码为：0x" + retRtn.ToString("x8"));
                    //    return;
                    //}
                    ////获取捆绑 PT 运动的状态
                    //retRtn = ImcApi.IMC_GetPtPackStatus(cardHandle, sysNo, ref Status0);
                    //if (retRtn != ImcApi.EXE_SUCCESS)
                    //{
                    //    ShowMessage("IMC_GetPtPackStatus failed 故障代码为：0x" + retRtn.ToString("x8"));
                    //    return;
                    //}
                    ////获取捆绑 PT 运动位置的编程类型
                    //retRtn = ImcApi.IMC_GetPtPackIncMode(cardHandle, sysNo, ref IncMode);
                    //if (retRtn != ImcApi.EXE_SUCCESS)
                    //{
                    //    ShowMessage("IMC_GetPtPackIncMode failed 故障代码为：0x" + retRtn.ToString("x8"));
                    //    return;
                    //}
                    ////获取捆绑 PT 运动数据断流保护的设置状态
                    //retRtn = ImcApi.IMC_GetPtPackNoDataProtectStatus(cardHandle, sysNo, EnSts, ThresholdVel);
                    //if (retRtn != ImcApi.EXE_SUCCESS)
                    //{
                    //    ShowMessage("IMC_GetPtPackNoDataProtectStatus failed 故障代码为：0x" + retRtn.ToString("x8"));
                    //    return;
                    //}
                    ////获取捆绑 PT 运动错误
                    //retRtn = ImcApi.IMC_GetPtPackError(cardHandle, sysNo, ref Err);
                    //if (retRtn != ImcApi.EXE_SUCCESS)
                    //{
                    //    ShowMessage("IMC_GetPtPackError failed 故障代码为：0x" + retRtn.ToString("x8"));
                    //    return;
                    //}
                    ////获取捆绑 PT 运动到位状态
                    //retRtn = ImcApi.IMC_PtPackGetArrivalSts(cardHandle, sysNo, ref Sts);
                    //if (retRtn != ImcApi.EXE_SUCCESS)
                    //{
                    //    ShowMessage("IMC_PtPackGetArrivalSts failed 故障代码为：0x" + retRtn.ToString("x8"));
                    //    return;
                    //}
                    //获取系统的剩余 FIFO 空间量
                    //retRtn = ImcApi.IMC_CrdGetFifoEmpty(cardHandle, crdNo, ref Empty);
                    //if (retRtn != ImcApi.EXE_SUCCESS)
                    //{
                    //    ShowMessage("IMC_CrdGetFifoEmpty failed 故障代码为：0x" + retRtn.ToString("x8"));
                    //    return;
                    //}
                }
                //PT状态
                textBox_PtPackStatus.Text = Status0.ToString();
                textBox_PtPackIncMode.Text = IncMode.ToString();
                textBox_PtPackNoDataProtectStatus.Text = EnSts.ToString();
                textBox_PtPackError.Text = Err.ToString();
                textBox_ArrivalSts.Text = Sts.ToString();
                textBox_FifoEmpt.Text = Empty.ToString();                

                timer_UI.Enabled = true;
            }
            catch (Exception ex)
            {
                ShowMessage(ex.ToString());
            }            
        }
        #endregion

        #region 功能测试
        //功 能： 建立多轴捆绑 PT 运行系统
        private void button_SetupPtPackSys_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    retRtn = ImcApi.IMC_SetupPtPackSys(cardHandle, sysNo, MaskAxNoArray, maxAxNum);
            //    if (retRtn != ImcApi.EXE_SUCCESS)
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " failed 故障代码为：0x" + retRtn.ToString("x8"));
            //    }
            //    else
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " 成功");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    ShowMessage(ex.ToString());
            //}
        }
        //功 能： 添加捆绑 PT 运动数据，实现多轴同频不同幅的一个周期的正弦速度规划运动。假设参与绑定PT运动的轴为0~2，共3个轴， 各轴的速度幅值分别为1000000p/s， 2000000 p/s， 3000000 p/s。,由于绑定PT设计的最大运动数据buf深度为256个， 该例程为一次将该周期数据压入后启动；
        private void button_AddMotionPointPtPack_Click(object sender, EventArgs e)
        {
            //try
            //{
                //Int32[] PosArray = new Int32[256*3];//建立系统中 pMaskAxNo[0]~ pMaskAxNo[N] 所对应的位置
                //Int16[] TypeArray = new Int16[256*3];//位置类型： 0 绝对， 1 相对
                //double T = 10 * 1000 / 256;//每个数据点执行的时间，单位：毫秒，计算间隔时间
                //Int16 dataNum = 256;//数据的个数
                //double[] velMax = { 10000, 20000, 30000 };//各轴的速度幅值
                //double vel = 0;//当前速度
                //double velOld = 0;//上一次速度
                //double tmpTime = 0;//临时变量

                ////正弦速度规划运动
                //for (int i = 0; i < dataNum; i++)
                //{
                //    for (int j = 0; j < count; j++)
                //    {
                //        vel = (velMax[j] * Math.Sin(2 * Math.PI * tmpTime));
                //        PosArray[i * count + j] = (Int32)((vel + velOld) * T * 0.5);
                //        TypeArray[i * count + j] = 0;
                //        velOld = vel;
                //    }
                //    tmpTime += T*0.001;//细分间隔1ms
                //}
            //}
            //catch (Exception ex)
            //{
            //    ShowMessage(ex.ToString());
            //}
        }
        //功 能： 添加捆绑 PT 中的 DO 输出事件
        private void button_AddDoPointPtPack_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    Int16 doNo = 0;//DO 输出的端口号
            //    Int16 doType = 0;//DO 输出的类型： 0： EtherCAT 类型 DO 1：本地端子板 DO
            //    Int16 doLevel = 1;//DO 输出电平 0： 低电平 1： 高电平
            //    retRtn = ImcApi.IMC_AddDoPointPtPack(cardHandle, sysNo, doNo, doType, doLevel);
            //    if (retRtn != ImcApi.EXE_SUCCESS)
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " failed 故障代码为：0x" + retRtn.ToString("x8"));
            //    }
            //    else
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " 成功");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    ShowMessage(ex.ToString());
            //}
        }
        //功 能： 启动捆绑 PT 运动
        private void button_StartPtPack_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    retRtn = ImcApi.IMC_StartPtPack(cardHandle, sysNo);
            //    if (retRtn != ImcApi.EXE_SUCCESS)
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " failed 故障代码为：0x" + retRtn.ToString("x8"));
            //    }
            //    else
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " 成功");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    ShowMessage(ex.ToString());
            //}
        }
        //功 能： 停止捆绑 PT 运动
        private void button_StopPtPack_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    Int16 type = 0;//停止类型 0： 平滑停止 1： 急停
            //    retRtn = ImcApi.IMC_StopPtPack(cardHandle, sysNo, type);
            //    if (retRtn != ImcApi.EXE_SUCCESS)
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " failed 故障代码为：0x" + retRtn.ToString("x8"));
            //    }
            //    else
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " 成功");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    ShowMessage(ex.ToString());
            //}
        }
        //功 能： 销毁捆绑 PT 运动系统
        private void button_DeletePtPackSys_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    retRtn = ImcApi.IMC_DeletePtPackSys(cardHandle, sysNo);
            //    if (retRtn != ImcApi.EXE_SUCCESS)
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " failed 故障代码为：0x" + retRtn.ToString("x8"));
            //    }
            //    else
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " 成功");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    ShowMessage(ex.ToString());
            //}            
        }
        //功 能： 清除捆绑 PT 运动数据
        private void button_ClrPtPackData_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    retRtn = ImcApi.IMC_ClrPtPackData( cardHandle, sysNo);
            //    if (retRtn != ImcApi.EXE_SUCCESS)
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " failed 故障代码为：0x" + retRtn.ToString("x8"));
            //    }
            //    else
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " 成功");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    ShowMessage(ex.ToString());
            //}
        }
        //功 能： 设置捆绑 PT 运动位置的编程类型
        private void button_SetPtPackIncMode_Click(object sender, EventArgs e)
        {            
            //try
            //{
            //    Int16 incMode = 0;//0：绝对位置编程 1：相对位置编程
            //    retRtn = ImcApi.IMC_SetPtPackIncMode(cardHandle, sysNo, incMode);
            //    if (retRtn != ImcApi.EXE_SUCCESS)
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " failed 故障代码为：0x" + retRtn.ToString("x8"));
            //    }
            //    else
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " 成功");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    ShowMessage(ex.ToString());
            //}
        }
        //功 能： 使能捆绑 PT 运动数据断流保护
        private void button_EnablePtPackNoDataProtect_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    double[] pThresholdVel = { 10000, 10000, 10000 };//系统各轴对应的速度阈值
            //    //当使能后，根据缓冲区是否有数据，同时判断各轴的速度是否大于设定的阈值。 如果系统中有任意一个轴的速度大于了设定的阈值，则进行断流保护，按照设定的平滑停加速度进行停止。
            //    retRtn = ImcApi.IMC_EnablePtPackNoDataProtect(cardHandle, sysNo, pThresholdVel);
            //    if (retRtn != ImcApi.EXE_SUCCESS)
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " failed 故障代码为：0x" + retRtn.ToString("x8"));
            //    }
            //    else
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " 成功");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    ShowMessage(ex.ToString());
            //}
        }
        //取消捆绑 PT 运动数据断流保护
        private void button_DisablePtPackNoDataProtect_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    retRtn = ImcApi.IMC_DisablePtPackNoDataProtect(cardHandle, sysNo);
            //    if (retRtn != ImcApi.EXE_SUCCESS)
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " failed 故障代码为：0x" + retRtn.ToString("x8"));
            //    }
            //    else
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " 成功");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    ShowMessage(ex.ToString());
            //}
        }
        //功 能： 清除捆绑 PT 运动错误
        private void button_ClrPtPackError_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    retRtn = ImcApi.IMC_ClrPtPackError(cardHandle, sysNo);
            //    if (retRtn != ImcApi.EXE_SUCCESS)
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " failed 故障代码为：0x" + retRtn.ToString("x8"));
            //    }
            //    else
            //    {
            //        ShowMessage(System.Reflection.MethodBase.GetCurrentMethod().Name + " 成功");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    ShowMessage(ex.ToString());
            //}
        }
        #endregion


    }
}
